<?php

namespace App\Common\Exception;

use App\Common\Util\Response;
use Psr\Http\Message\ResponseInterface;

/**
 * Class ApiDataException
 */
class ApiDataException extends \Exception implements ApiResponseExceptionInterface
{
    public function __construct(protected mixed $data = "", int $code = 200, ?\Throwable $previous = null)
    {
        parent::__construct('api data', $code, $previous);
    }

    /**
     * 响应
     *
     * @return \think\Response
     */
    public function response(): \think\Response
    {
        return Response::json()->body($this->getCode(), $this->message, $this->data);
    }
}
